package com.hf.security

import grails.converters.JSON

import com.hf.init.InitService
import com.hf.order.MailOrderService

class AdminOperationController {

	InitService initService
	MailOrderService mailOrderService
	SystemConfigService systemConfigService

	def index() {
		AdminOperationCommand command = new AdminOperationCommand()
		command.isRainday =systemConfigService.getIsRainDay()
		command.billDay =systemConfigService.getBillDayOfPeriod()
		render view: '/order/admin/adminOperation',model: [command : command]
	}

	// ajax
	def sendOrderMail() {
		log.info "send order mail!"

		initService.init()
		mailOrderService.sendMail()

		log.info "order email success"

		render  [:] as JSON
	}

	// ajax
	def updateRainDay(boolean isRainDay) {

		systemConfigService.setRainDay(isRainDay)

		render [:] as JSON
	}

	// ajax
	def updateBillDay(int billDay) {

		systemConfigService.setBillDayOfPeriod(billDay)

		Map resultMap = [:]
		render [:] as JSON
	}

}

class AdminOperationCommand {
	boolean isRainday
	int billDay
}
